package com.talkweb.yingu.apimodel.admin;

import lombok.Getter;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by qsf on 2019/4/3.
 */
@Setter
@Getter
public class TreeNodeVo {

    private String id;
    private String name;
    private String parentId;
    private List<TreeNodeVo> children;
    private String level;
    private String orgType;
    private String validateState;

    public static List<TreeNodeVo> treeBuild(List<TreeNodeVo> list) {
        List<TreeNodeVo> treeNodeList = new ArrayList<>();

        for(TreeNodeVo node1: list) {
            boolean flag= false;
            for(TreeNodeVo node2 : list) {
                if(node1.getParentId()!=null && node1.getParentId().equals(node2.getId())) {
                    flag = true;
                    if(node2.getChildren()== null) {
                        node2.setChildren(new ArrayList<TreeNodeVo>());
                    }
                    node2.getChildren().add(node1);
                    break;
                }

            }
            if(!flag) {
                treeNodeList.add(node1);
            }
        }
        return treeNodeList;

    }
}
